package middleware

import (
	"fmt"
	"github.com/gofiber/fiber/v2"
	"github.com/gofiber/fiber/v2/middleware/basicauth"
	"go-fiber-rest-api/config"
)

func AuthReq() fiber.Handler {
	fmt.Println(config.Config("USERNAME"))
	fmt.Println(config.Config("PASSWORD"))
	cfg := basicauth.Config{
		Users: map[string]string{
			config.Config("USERNAME"): config.Config("PASSWORD"),
		},
		Authorizer: func(user, pass string) bool {
			if user == config.Config("USERNAME") && pass == config.Config("PASSWORD") {
				return true
			}
			return false
		},
	}
	handle := basicauth.New(cfg)
	return handle
}
